package com.sltx.controller;

import com.sltx.controller.base.BaseController;
import com.sltx.service.CyflService;
import com.sltx.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping(value = "/cyfl")
public class CyflController extends BaseController {

    @Autowired
    private CyflService cyflService;

    @RequestMapping("/getCyflList")
    @ResponseBody
    public Object getCyflList(HttpServletRequest request){
        Map<String,Object> result = new HashMap();
        PageData pd = this.getPageData();
        int pageSize = Integer.parseInt(pd.get("pageSize").toString());
        int pageNo = Integer.parseInt(pd.get("pageNo").toString());
        Integer startPage = ((pageSize*(pageNo-1)));//每页其实值
        pd.put("startPage",startPage.toString());//每页个数
        result.put("num",cyflService.getNum());
        result.put("list",cyflService.getCyflList(pd));
        return result;
    }


    @RequestMapping("/getCyflByName")
    @ResponseBody
    public Object getCyflByName(HttpServletRequest request){
        Map<String,Object> result = new HashMap();
        PageData pd = this.getPageData();

        int pageSize = Integer.parseInt(pd.get("pageSize").toString());
        int pageNo = Integer.parseInt(pd.get("pageNo").toString());

        Integer startPage = ((pageSize*(pageNo-1)));
        Integer endPage = startPage+pageSize;

        pd.put("startPage",startPage.toString());
        pd.put("endPage",endPage.toString());

        if ("产业分类".equals(pd.get("pf"))){
            pd.remove("pf");
        }

        result.put("num",cyflService.getCyflByNameNum(pd));
        result.put("list",cyflService.getCYflByName(pd));

        return result;
    }


}
